<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">店铺管理</a>
        <a>
          <cite>临时菜品</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row" style="text-align: center">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="food_name"  placeholder="请输入菜名" autocomplete="off" class="layui-input">
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn" onclick="x_admin_show('添加菜品','{:url("foods/temporaryAdd")}',451,350)"><i class="layui-icon"></i>添加</button>
    </xblock>
    <table id="demo" lay-filter="test"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="confirm">修改</a>
        <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>
<script>
    layui.use(['form','table'], function(){
        var form = layui.form
            ,table = layui.table;

        var tableIns= table.render({
            elem: '#demo'
            ,url: '{:url("foods/temporaryData")}' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', fixed: 'left'}
                ,{field: 'food_name', title: '菜品名称'}
                ,{field: 'shop_id', title: '所属店铺'}
                ,{field: 'price', title: '单价'}
                ,{field: 'create_time', title: '添加时间'}
                ,{field: 'status', title: '状态',templet: function(d){
                        if (d.status == 1){
                            return '<span class=\'layui-btn layui-btn-xs layui-btn-normal\'>正常</span>';
                        }else {
                            return '<span class=\'layui-btn layui-btn-xs layui-btn-danger\'>禁用</span>';
                        }
                    }}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:130}
            ]]
        });
        form.on('submit(sreach)',function (data) {
            tableIns.reload({
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });
        table.on('tool(test)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'confirm'){ //查看
                x_admin_show('菜品修改','{:url("foods/temporaryEdit")}?id='+data.id,451,350);
            } else if(layEvent === 'del'){ //删除
                layer.confirm('真的删除行么', function(index){
                    $.post('{:url("foods/temporaryDel")}',{id:data.id},function (res) {
                        if (res.code==1){
                            layer.msg(res.msg,{icon:6,time:1000},function () {
                                layer.close(index);
                                obj.del();
                            });
                        } else {
                            layer.msg(res.msg,{icon:5,time:1000},function () {
                                layer.close(index);
                            });
                        }
                    });
                });
            }
        });
    });

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!',{icon:1,time:1000});
        });
    }
</script>
</body>

</html>